﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConverterInterface;

namespace DelphiConverterLibrary
{
    public class StateMachine
    {
        private StringBuilder buffer;

        DelphiConverter owner;
        State currentState;
        State previousState;
        bool finished;

        public StateMachine(DelphiConverter owner)
        {
            buffer = new StringBuilder(50);
            this.owner = owner;
            finished = false;
            currentState = NothingState.Instance;
        }

        public bool Finished
        {
            get { return finished; }
            set { finished = value; }
        }

        public StringBuilder Buffer
        {
            get { return buffer; }
            set { buffer = value; }
        }



        public void Update()
        {
            currentState.Execute(owner);
        }

        public void ChangeState(State state)
        {
            previousState = currentState;
            currentState.Exit(owner);
            currentState = state;
            currentState.Enter(owner);
        }

        public void ReturnToPreviousState()
        {
            ChangeState(previousState);
        }

    }
}
